const Koa=require('koa2');
const config=require('./config');
const app=new Koa();

app.keys=config.keys;
app.use(require('koa-logger')());
app.use(require('koa-session')(config.session,app));
app.use(require('koa-handlebars-next')({
    cache:'development'!==app.env,
    defaultLayout:'main',
    layoutsDir:'views/layouts',
    partialsDir:'views/partials',
    helpers:{
        section(name, opts){
            if(!this._sections)this._sections={};
            this._sections[name]=opts.fn(this);
            return null;
        }
    }
}));

require('./routes/index')(app);

app.listen(3030,()=>{
    console.log(`\n\nkoa-session port:3030 ${new Date().toLocaleString()}`);
});